#include <gflags/gflags.h>
#include "spdlogger.hpp"
#include "etcd.hpp"
#include <thread>

/*
    测试二次封装的etcd的服务注册类
*/

DEFINE_bool(mode, false, "日志输出模式，true:发布模式，false:调试模式");
DEFINE_int32(release_level, 0, "发布模式下日志记录等级，此等级以上日志都记录");
DEFINE_string(file, "file.txt", "发布模式下日志输出文件");

DEFINE_string(etcd_url, "http://127.0.0.1:2379", "客户端访问etcd服务的url");
DEFINE_string(server_base_dir, "/services", "服务根目录");
DEFINE_string(instance1_name, "/use", "实例名称");
DEFINE_string(instance1_host, "127.0.0.1:8888", "实例节点的ip&&port");
DEFINE_string(instance2_name, "/server", "实例名称");
DEFINE_string(instance2_host, "127.0.0.1:9999", "实例节点的ip&&port");


int main(int argc, char* argv[])
{
    // 解析命令行参数
    google::ParseCommandLineFlags(&argc, &argv, true);

    // 初始化日志记录器
    ns_spdlogger::init_logger(FLAGS_mode, FLAGS_release_level, FLAGS_file);

    // 服务注册对象
    shared_ptr<ns_etcd::Registry> rgs = make_shared<ns_etcd::Registry>(FLAGS_etcd_url);
    rgs->registry(FLAGS_server_base_dir + FLAGS_instance1_name, FLAGS_instance1_host); // 注册服务1
    rgs->registry(FLAGS_server_base_dir + FLAGS_instance2_name, FLAGS_instance2_host); // 注册服务2

    std::this_thread::sleep_for(std::chrono::seconds(500));

    return 0;
}